From caea654f126c9b774407a0467698a8528f58a9f7 Mon Sep 17 00:00:00 2001 From: robertl Date: Tue, 31 Oct 2006 16:53:32 +0000 Subject: [PATCH] Track average and extreme heart rate and cadence for KML writer. Whitespace fixes. --- defs.h | 5 +++++ kml.c | 32 ++++++++++++++++++++++++-------- route.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 69 insertions(+), 12 deletions(-) diff --git a/defs.h b/defs.h index 0bb9a2e87..4236e79aa 100644 --- a/defs.h +++ b/defs.h @@ -380,8 +380,13 @@ typedef struct { double min_alt; double max_spd; /* Meters/sec */ double min_spd; /* Meters/sec */ + double avg_hrt; /* Avg Heartrate */ + double avg_cad; /* Avg Cadence */ time_t start; /* Min time */ time_t end; /* Max time */ + int min_hrt; /* Min Heartrate */ + int max_hrt; /* Max Heartrate */ + int max_cad; /* Max Cadence */ } computed_trkdata; /* diff --git a/kml.c b/kml.c index 41fa5f491..a3851342c 100644 --- a/kml.c +++ b/kml.c @@ -449,6 +449,22 @@ void kml_output_trkdescription(const route_head *header, computed_trkdata *td) double spd = fmt_speed(td->max_spd, &spd_units); TD2("Max Speed %.1f %s", spd, spd_units); } + if (td->avg_hrt) { + TD("Avg Heart Rate %.1f bpm", td->avg_hrt); + } + if (td->min_hrt < td->max_hrt) { + TD("Min Heart Rate %d bpm", td->min_hrt); + } + if (td->max_hrt) { + TD("Max Heart Rate %d bpm", td->max_hrt); + } + if (td->avg_cad) { + TD("Avg Cadence %.1f rpm", td->avg_cad); + } + if (td->max_cad) { + TD("Max Cadence %d rpm", td->max_cad); + } + kml_write_xml(-1, "]]>\n"); kml_write_xml(-1, "\n"); @@ -468,15 +484,15 @@ void kml_output_trkdescription(const route_head *header, computed_trkdata *td) static void kml_output_header(const route_head *header, computed_trkdata*td) { - kml_write_xml(1, "\n"); + kml_write_xml(1, "\n"); kml_write_xmle("name", header->rte_name); kml_output_trkdescription(header, td); - if (export_points && header->rte_waypt_ct > 0) { - // Put the points in a subfolder - kml_write_xml(1, "\n"); - kml_write_xml(0, "Points\n"); - } + if (export_points && header->rte_waypt_ct > 0) { + // Put the points in a subfolder + kml_write_xml(1, "\n"); + kml_write_xml(0, "Points\n"); + } // Create an array for holding waypoint coordinates so that we // can produce a LineString at the end. @@ -801,7 +817,7 @@ void kml_write(void) kml_write_xml(1, "\n"); @@ -825,7 +841,7 @@ void kml_write(void) if (!realtime_positioning) { kml_write_xml(-1, "\n"); } - + // Output routes if (!realtime_positioning) { kml_write_xml(1, "\n"); diff --git a/route.c b/route.c index 6760c4036..39130834f 100644 --- a/route.c +++ b/route.c @@ -67,7 +67,7 @@ route_head_alloc(void) route_head *rte_head; rte_head = (route_head *) xcalloc(sizeof (*rte_head), 1); QUEUE_INIT(&rte_head->Q); - QUEUE_INIT(&rte_head->waypoint_list); + QUEUE_INIT(&rte_head->waypoint_list); return rte_head; } @@ -93,7 +93,7 @@ any_route_free(route_head *rte) static void any_route_add_head( route_head *rte, queue *head ) { - ENQUEUE_TAIL( head, &rte->Q ); + ENQUEUE_TAIL( head, &rte->Q ); } static void @@ -313,7 +313,7 @@ route_flush( queue *head ) { queue *elem, *tmp; queue *q; - QUEUE_FOR_EACH(head, elem, tmp ) { + QUEUE_FOR_EACH(head, elem, tmp ) { q = dequeue(elem); any_route_free((route_head *)q); } @@ -328,7 +328,7 @@ route_copy( int *dst_count, int *dst_wpt_count, queue **dst, queue *src ) { dst_wpt_count = &junk; } - if ( !*dst ) { + if ( !*dst ) { *dst = xcalloc( 1, sizeof( queue )); QUEUE_INIT( *dst ); *dst_count = 0; @@ -490,6 +490,10 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) waypoint *prev = &first; queue *elem, *tmp; int tkpt = 0; + int pts_hrt = 0; + double tot_hrt = 0.0; + int pts_cad = 0; + double tot_cad = 0.0; char tkptname[100]; computed_trkdata *tdata = xcalloc(1, sizeof (computed_trkdata)); @@ -500,6 +504,7 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) first.latitude = 0; first.longitude = 0; first.creation_time = 0; + tdata->min_hrt = 9999; tdata->min_alt = 999999999; tdata->max_alt = -999999999; @@ -548,6 +553,28 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) tdata->max_alt = this->altitude; } + if (this->heartrate > 0) { + pts_hrt++; + tot_hrt += (float) this->heartrate; + } + + if ((this->heartrate > 0) && (this->heartrate < tdata->min_hrt)) { + tdata->min_hrt = (int) this->heartrate; + } + + if ((this->heartrate > 0) && (this->heartrate > tdata->max_hrt)) { + tdata->max_hrt = (int) this->heartrate; + } + + if (this->cadence > 0) { + pts_cad++; + tot_cad += (float) this->cadence; + } + + if ((this->cadence > 0) && (this->cadence > tdata->max_cad)) { + tdata->max_cad = (int) this->cadence; + } + if (this->creation_time && (this->creation_time < tdata->start)) { tdata->start = this->creation_time; } @@ -566,6 +593,15 @@ void track_recompute(const route_head *trk, computed_trkdata **trkdatap) } tkpt++; } + + if (pts_hrt > 0) { + tdata->avg_hrt = tot_hrt / (float) pts_hrt; + } + + if (pts_cad > 0) { + tdata->avg_cad = tot_cad / (float) pts_cad; + } + if (!trkdatap) { xfree(tdata); } -- 2.30.2